package com.tywj.buscustomerapp.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.tywj.buscustomerapp.Config;
import com.tywj.buscustomerapp.model.bean.CityBean;

public class SPUtils {

    public static void rememberIsStation(Context context,boolean isCall){
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO,0);
        setting.edit().putBoolean(Config.IS_CALL,isCall).commit();

    }

    public static boolean getIsStation(Context context){
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO,0);
        boolean is = setting.getBoolean(Config.IS_CALL,true);
        return is;
    }

    public static void rememberUser(Context context,String phone,String uImei){
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO,0);
        setting.edit().putString(Config.USER_PHONE,phone)
                .putString(Config.USER_IMEI,uImei).commit();
    }

    public static String getUserPhone(Context context){
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO,0);
        String phone = setting.getString(Config.USER_PHONE,"");
        return phone;
    }

    public static String clearUserPhone(Context context){
        SharedPreferences sp = context.getSharedPreferences(Config.STRING_INFO,
                Context.MODE_PRIVATE);
        sp.edit().putString(Config.USER_PHONE,null)
                .commit();
        return null;
    }

    public static void rememberStart(Context context, String start,String lat,String lng){
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO, 0);
        setting.edit().putString(Config.START_TITLE, start)
                .putString(Config.START_LAT,lat)
                .putString(Config.START_LNG,lng)
                .commit();
    }

    public static void rememberEnd(Context context, String end,String lat,String lng){
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO, 0);
        setting.edit().putString(Config.END_TITLE,end)
                .putString(Config.END_LAT,lat)
                .putString(Config.END_LNG,lng)
                .commit();
    }

    public static String[]  getStartAndEnd(Context context){
        String[] address = new String[2];
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO, 0);
        address[0] = setting.getString(Config.START_TITLE,"");
        address[1] = setting.getString(Config.END_TITLE,"");
        return address;
    }

    public static double[]  getStartAndEndLatLng(Context context){
        double[] address = new double[4];
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO, 0);
        address[0] = Double.valueOf(setting.getString(Config.START_LAT,"0"));
        address[1] = Double.valueOf(setting.getString(Config.START_LNG,"0"));
        address[2] = Double.valueOf(setting.getString(Config.END_LAT,"0"));
        address[3] = Double.valueOf(setting.getString(Config.END_LNG,"0"));
        return address;
    }

    public static void clearStartAndEnd(Context context) {
        SharedPreferences sp = context.getSharedPreferences(Config.STRING_INFO,
                Context.MODE_PRIVATE);
        sp.edit().putString(Config.START_TITLE,null)
                .putString(Config.START_TITLE,null)
                .commit();
    }

    public static void rememberCity(Context context, CityBean city){
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO, 0);
        setting.edit().putString(Config.CITY_NAME, city.getCityName())
                .putString(Config.CITY_ID,city.getCityId())
                .commit();
    }

    public static CityBean getCity(Context context){
        CityBean city =new CityBean();
        SharedPreferences setting = context.getSharedPreferences(Config.STRING_INFO, 0);
        city.setCityName(setting.getString(Config.CITY_NAME,"成都"));
        city.setCityId(setting.getString(Config.CITY_ID,"001"));
        return city;
    }
}
